home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 47.7z / BS1 part 47 / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 1 of 7)[HD].7z / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 1 of 7)[HD].adf / dd.lzh / progress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-30  |  4.2 KB  |  176 lines

  1. /*
  2.  * Progress.c - for showing a progress window on Imagemaster
  3.  */
  4. #include "system.h"
  5.  
  6. struct Library *IntuitionBase;
  7. struct Library *GfxBase;
  8. struct Library *ExecBase;
  9.  
  10. int openlibraries()
  11.   {
  12.     if (!(ExecBase = OpenLibrary("exec.library",37)))
  13.       {
  14.         printf("Could not open exec.library\n");
  15.         return(1);
  16.       }
  17.     if (!(IntuitionBase = OpenLibrary("intuition.library",0)))
  18.       {
  19.         printf("Could not open intuition.library\n");
  20.         return(2);
  21.       }
  22.     if (!(GfxBase = OpenLibrary("graphics.library",0)))
  23.       {
  24.         printf("Could not open graphics.library\n");
  25.         return(3);
  26.       }
  27.     return(0);
  28.   }
  29.  
  30. int closelibraries()
  31.   {
  32.     if (GfxBase)       CloseLibrary(GfxBase);
  33.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  34.     if (ExecBase)      CloseLibrary(ExecBase);
  35.     return(0);
  36.   }
  37.  
  38. struct NewWindow newwindow = {
  39.   20,10,  /* window XY origin relative to TopLeft of screen */
  40.   600,38,  /* window width and height */
  41.   0,1,  /* detail and block pens */
  42.   MOUSEBUTTONS|RAWKEY|MOUSEMOVE,  /* IDCMP flags */
  43.   RMBTRAP|BORDERLESS|NOCAREREFRESH|REPORTMOUSE,  /* other window flags */
  44.   NULL,  /* first gadget in gadget list */
  45.   NULL,  /* custom CHECKMARK imagery */
  46.   NULL,  /* window title */
  47.   NULL,  /* custom screen pointer */
  48.   NULL,  /* custom bitmap */
  49.   5,5,  /* minimum width and height */
  50.   640,200,  /* maximum width and height */
  51.   CUSTOMSCREEN  /* destination screen type */
  52. };
  53.  
  54. static struct Window *pwindow;      /* The progress window         */
  55. static int barx1,barx2,bary1,bary2; /* The progress bar location   */
  56. static int lastpos,maxpos;          /* The current progress extent */
  57.  
  58. #define BLACK   0 /* Imagemaster's panel colors */
  59. #define WHITE   1
  60. #define GRAY1   2
  61. #define GRAY3   3
  62. #define RED     4
  63. #define BLUE    5
  64. #define GREEN   6
  65. #define GRAY2   7
  66.  
  67. int progressbegin(struct Screen *imscr,int max,char *title)
  68.   {
  69.   int xw,yw,p;
  70.   struct RastPort *rp;
  71.   
  72.     /* First: Open the window */
  73.     if (!imscr)
  74.       {
  75.         printf("The Imagemaster screen was not located\n");
  76.         return(1);
  77.       }
  78.     newwindow.Screen = imscr;
  79.     if ((pwindow=(struct Window *)OpenWindow(&newwindow)) == NULL)
  80.       {
  81.         printf("Open window failed\n");
  82.         return(2);
  83.       }
  84.     
  85.     /* Next: draw the background */
  86.     /* We do not use black because it is transparent when overlayed */
  87.     xw = pwindow->Width;
  88.     yw = pwindow->Height;
  89.     rp = pwindow->RPort;
  90.     SetAPen(rp,GRAY2);
  91.     RectFill(rp,0,0,xw-1,yw-1);
  92.     SetAPen(rp,GRAY3);
  93.     Move(rp,0,yw-1);
  94.     Draw(rp,0,0);
  95.     Draw(rp,xw-1,0);
  96.     Move(rp,1,yw-2);
  97.     Draw(rp,1,1);
  98.     Draw(rp,xw-2,1);
  99.     SetAPen(rp,GRAY1);
  100.     Move(rp,1,yw-1);
  101.     Draw(rp,xw-1,yw-1);
  102.     Draw(rp,xw-1,1);
  103.     Move(rp,2,yw-2);
  104.     Draw(rp,xw-2,yw-2);
  105.     Draw(rp,xw-2,2);
  106.     
  107.     /* Next: draw the bar */
  108.     barx1 = 20;
  109.     barx2 = xw-20;
  110.     bary1 = 10;
  111.     bary2 = 16;
  112.     SetAPen(rp,GRAY3);
  113.     Move(rp,barx1-2,bary2+2);
  114.     Draw(rp,barx1-2,bary1-2);
  115.     Draw(rp,barx2+2,bary1-2);
  116.     SetAPen(rp,GRAY1);
  117.     Move(rp,barx2+2,bary1-1);
  118.     Draw(rp,barx2+2,bary2+2);
  119.     Draw(rp,barx1-1,bary2+2);
  120.     maxpos = max;
  121.     if (maxpos == 0) maxpos = 1;
  122.     lastpos = 0;
  123.     
  124.     /* Next Draw the text */
  125.     p = (barx1+barx2)/2 - strlen(title)*4;
  126.     SetAPen(rp,GRAY1);
  127.     SetDrMd(rp,JAM1);
  128.     Move(rp,p,pwindow->Height-7);
  129.     Text(rp,title,strlen(title));
  130.     Move(rp,barx1-8,bary2+10);
  131.     Text(rp,"0 %",3);
  132.     Move(rp,barx2-24,bary2+10);
  133.     Text(rp,"100 %",5);
  134.     
  135.     return(0);
  136.   }
  137.  
  138. int progressupdate(int y)
  139.   {
  140.   int x1,x2;
  141.   struct RastPort *rp;
  142.   
  143.     /* Some safety checks */
  144.     if (!pwindow) return(0);
  145.     if (y < 0) y = 0;
  146.     if (y > maxpos) y = maxpos;
  147.     rp = pwindow->RPort;
  148.     
  149.     /* Determine how much to redraw */
  150.     x1 = barx1 + lastpos * (barx2-barx1) / maxpos;
  151.     x2 = barx1 + y       * (barx2-barx1) / maxpos;
  152.     
  153.     /* Now draw in the achieved area */
  154.     
  155.     if (x2 < x1)            /* We went backwards */
  156.       {
  157.         SetAPen(rp,GRAY1);
  158.         RectFill(rp,x2,bary1,x1,bary2);
  159.       }
  160.     else if (x1 < x2)       /* This is forewards */
  161.       {
  162.         SetAPen(rp,BLUE);
  163.         RectFill(rp,x1,bary1,x2,bary2);
  164.       }
  165.     
  166.     lastpos = y;
  167.     return(0);
  168.   }
  169.  
  170. int progressend()
  171.   {
  172.     if (!pwindow) return(1);
  173.     CloseWindow(pwindow);
  174.     pwindow = NULL;
  175.     return(0);
  176.   }